package bl.commodity;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;

import po.CommodityTypePo;
import po.Po;
import blservice.commodity.CommodityTypeBLService;
import vo.CommodityTypeVo;
import vo.Vo;
import dbservice.commodity.CommodityTypeDBService;
import dbservice.history.SystemLogDBService;

public class CommodityTypeBL extends UnicastRemoteObject implements CommodityTypeBLService{
	private static final long serialVersionUID = 5876900526098116153L;
	CommodityTypeDBService commodityTypeDB;
    SystemLogDBService log;
    
    public CommodityTypePo _po(CommodityTypeVo vo){
    	CommodityTypePo po=new CommodityTypePo();
    	po.set名称(vo.get名称());
    	po.set父节点(vo.get父节点());
    	po.set编号(vo.get编号());
    	po.set是叶节点(vo.get是叶节点());
    	return po;
    }
	public CommodityTypeVo _vo(CommodityTypePo po){
		CommodityTypeVo vo=new CommodityTypeVo();
		vo.set编号(po.get编号());
		vo.set名称(po.get名称());
		vo.set父节点(po.get父节点());
		vo.set是叶节点(po.get是叶节点());
		return vo;
	}
    public CommodityTypeBL(CommodityTypeDBService commodityTypeDB,SystemLogDBService log)throws RemoteException{
		this.commodityTypeDB=commodityTypeDB;
		this.log=log;
		
	}
	
	public Vo addCommodityType(CommodityTypeVo vo) {
		Po po=commodityTypeDB.add(_po(vo));
		Vo r=new Vo();
		if(po.isSuccessed()){
			r.successed();
		}else{
			r.failed(po.getFailMessage());
		}
		return r;
	}

	public Vo deleteCommodityType(CommodityTypeVo vo) {
		Po po=commodityTypeDB.delete(_po(vo));
		Vo r=new Vo();
		if(po.isSuccessed()){
			r.successed();
		}else{
			r.failed(po.getFailMessage());
		}
		return r;
	}

	public Vo updateCommodityType(CommodityTypeVo vo) {
		Po po=commodityTypeDB.update(_po(vo));
		Vo r=new Vo();
		if(po.isSuccessed()){
			r.successed();
		}else{
			r.failed(po.getFailMessage());
		}
		return r;
	}
	@Override
	public List<CommodityTypeVo> getAll() throws RemoteException {
		List<CommodityTypeVo> vo_list=new ArrayList<CommodityTypeVo>(); 
		List<CommodityTypePo> po_list=commodityTypeDB.getAll();
		for(int i=0;i<po_list.size();i++){
			vo_list.add(_vo(po_list.get(i)));
		}
		return vo_list;
	}
	@Override
	public List<CommodityTypeVo> getLeaf() throws RemoteException {
		List<CommodityTypeVo> vo_list=new ArrayList<CommodityTypeVo>(); 
		List<CommodityTypePo> po_list=commodityTypeDB.getLeaf();
		for(int i=0;i<po_list.size();i++){
			vo_list.add(_vo(po_list.get(i)));
		}
		return vo_list;
	}
	@Override
	public List<CommodityTypeVo> getFatherAbleType() throws RemoteException {
		List<CommodityTypeVo> vo_list=new ArrayList<CommodityTypeVo>(); 
		List<CommodityTypePo> po_list=commodityTypeDB.getFatherAbleType();
		for(int i=0;i<po_list.size();i++){
			vo_list.add(_vo(po_list.get(i)));
		}
		return vo_list;
	}
	
}